const app = getApp()
Page({
  data: {
    coupon:[],
  },
  //生命周期函数--监听页面显示
  onShow: function (){
    this.couponApi();
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(()=>{
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.setData({
      loading: true,
      page:0,
      coupon:[]
    });
    this.couponApi();
  },
  //读取优惠券
  couponApi: function () {
    app.api().Get('api/v1/ais/gmcoupon/index',(result) => {
      this.setData({
        coupon:  result.data,
      });
    })
  },
  //查看优惠券规则
  reCoupon:function(e){
     wx.navigateTo({
       url:e.currentTarget.dataset.url,
       fail: (res) => {
         app.wxAlert('未找到页面')
       }
     })
  },
  //Tab切换
  onTabChange:function(event){
    this.setData({
      active: event.detail.name,
      loading: true,
      page:0,
      coupon:[]
    });
    this.couponApi();
  },
  //滚动
  onPageScroll(res){
    let scrollTop = res.scrollTop;
    this.setData({
      showbar: 150 <= scrollTop ?true :false
    })
  },
  onCreate: function () {
		wx.navigateTo({
			url: 'create',
		})
	},
})